<DOCTYPE HTML>
    <html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <script type="text/javascript">

            var uidServiceData = '${UID_SERVICE_MAPPING}';
            var uidToServiceName = JSON.parse(uidServiceData);
            var uidClientNameData = '${UID_CLIENT_CLASS_MAPPING}';
            var uidToClientPrefix = JSON.parse(uidClientNameData);
            // A mapping from uid to the list of operations that are only available on the async client
            var uidToAsyncOnlyOperationData = '${SERVICE_NAME_TO_ASYNC_ONLY_OPERATION_MAPPING}';
            var uidToAsyncOnlyOperations = JSON.parse(uidToAsyncOnlyOperationData)
            var baseUri = window.location.href;
            var serviceFolderPath = "software/amazon/awssdk/services/";

            function getQueryStringParameter(name, url) {

                var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
                name = name.replace(/[\[\]]/g, "\\$&");
                results = regex.exec(url);
                if (!results) return null;
                if (!results[2]) return '';
                return decodeURIComponent(results[2].replace(/\+/g, " "));
            }

            function camelize(str) {
                return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
                    return index === 0 ? word.toLowerCase() : word.toUpperCase();
                }).replace(/\s+/g, '');
            }

            function checkResourceExists(url) {
                try {
                    var xmlHttp = new XMLHttpRequest();
                    xmlHttp.open( "GET", url, false );
                    xmlHttp.send( null );
                    return xmlHttp.status == 200;
                }
                catch(err) {
                    return false;
                }
            }

            function requestSignature(uid, serviceName, typeName) {
                var pkgBase = "software.amazon.awssdk.services." + serviceName + ".model.";
                var requestObjectName = typeName + "Request";

                var params = pkgBase + requestObjectName;

                if (isAsyncOnlyMethod(uid, typeName)) {
                    eventStreamInfo = uidToAsyncOnlyOperations[uid][typeName];
                    if (eventStreamInfo['input'] === true) {
                        params = params + ",org.reactivestreams.Publisher";
                    }

                    if (eventStreamInfo['output'] === true) {
                        params = params + "," + pkgBase + typeName + "ResponseHandler";
                    }
                }

                return "(" + params + ")"
            }

            function isAsyncOnlyMethod(uid, typeName) {
                return uidToAsyncOnlyOperations[uid] != null && uidToAsyncOnlyOperations[uid][typeName] != null;
            }

            function asyncClientName(uid) {
                return uidToClientPrefix[uid] + "AsyncClient";
            }

            function syncClientName(uid) {
                return uidToClientPrefix[uid] + "Client";
            }

            var typeName = getQueryStringParameter("type", window.location.href);
            var operation = getQueryStringParameter("operation", window.location.href);
            var uid = getQueryStringParameter("uid", window.location.href);
            var clientObjectName =  syncClientName(uid);
            var serviceName =  uidToServiceName[uid];
            var redirectSuffixLink = "index.html"

            if(clientObjectName != null && serviceName != null) {
                redirectServiceSuffixLink = serviceFolderPath + serviceName + "/model/" + typeName + ".html" ;
                if(checkResourceExists( baseUri.replace(/crosslink_redirect.*/gi, redirectServiceSuffixLink) )) {
                    redirectSuffixLink =  redirectServiceSuffixLink;
                } else {
                    redirectServiceSuffixLink =  serviceFolderPath + serviceName + "/";
                    if(typeName != null) {
                        if (isAsyncOnlyMethod(uid, typeName)) {
                            clientObjectName = asyncClientName(uid);
                        }
                        redirectServiceSuffixLink = redirectServiceSuffixLink + clientObjectName + ".html" ;
                        methodName = camelize(typeName);
                        redirectServiceSuffixLink =
                            redirectServiceSuffixLink +
                            "#" +
                            methodName + requestSignature(uid, serviceName, typeName);
                    } else {
                        redirectServiceSuffixLink = redirectServiceSuffixLink + clientObjectName + ".html" ;
                    }

                    if(checkResourceExists( baseUri.replace(/crosslink_redirect.*/gi, redirectServiceSuffixLink) )) {
                        redirectSuffixLink =  redirectServiceSuffixLink;
                    }
                }
            }
            window.location.href = redirectSuffixLink ;
        </script>
    </head>
    <body>
    </body>
</html>